function isf = isBVQXinifile(hfile, isvalid)
% isBVQXinifile  - perform validity check on input
%
% FORMAT:       isfile = isBVQXinifile(test [, isvalid])
%
% Input fields:
%
%       test        variable to test
%
% Output fields:
%
%       isfile      1x1 false for non-matching classes or 1xN logical,
%                   true if OK, false if no longer in memory (if isvalid)

% Version:  v0.7f
% Build:    8110521
% Date:     Nov-05 2008, 9:00 PM CET
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% basic argument check
if nargin < 1
    error( ...
        'BVQXtools:BadArgument', ...
        'Call requires at least one input argument.' ...
    );
end

% initialise output
isf = isa(hfile, 'BVQXinifile');
if ~isf || ...
    nargin < 2 || ...
   ~islogical(isvalid) || ...
    isempty(isvalid)
    return;
end
isf = false(size(hfile));

% iterate over objects
for hc = 1:numel(hfile)
    isf(hc) = BVQXinifile(hfile(hc), 'isvalid');
end
